package com.njupt.towersusers.controller;

import com.njupt.towersusers.domain.Drivers;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/usr")
@CrossOrigin("*")
public class driverContr {
    @RequestMapping("/insertUser")
    public String insert(
            Drivers driver,
            MultipartFile usphoto,
            MultipartFile drivercard
    ){
//        调用服务器类将文件保存为临时文件
//        在将临时文件上传到fastfs文件服务器上 并获得服务器上的返回图片路劲
//        再将
        return "{\"driverreg\":\"success\"}";
    }
    @RequestMapping("/userdel/{driverid}")
    public String del(@PathVariable("driverid") int driverid){
        System.out.println(driverid);
        return "{\"driverdestory\":\"success\"}";
    }

    @RequestMapping("/usermod")
    public String mod(Drivers drivers){
        return "{\"drivermodify\":\"success\"}";
    }
    @RequestMapping("usercheck")
    public List<Drivers> finduser(){
        ArrayList<Drivers> drs = new ArrayList<>();
        drs.add(Drivers.builder().drivername("zs").driverid(12)
                .driverage(40).build());
        drs.add(Drivers.builder().drivername("ls").driverid(13)
                .driverage(40).build());
        return drs;
    }
    @RequestMapping("/findUserByCondition")
    public List<Drivers> findCond(Drivers drivers){
        ArrayList<Drivers> drs = new ArrayList<>();
        drs.add(Drivers.builder()
                .drivername("张三").driverid(32)
                .driverage(23).build());
        drs.add(Drivers.builder()
                .drivername("胡伟").driverid(12)
                .driverage(50).build());
        return drs;

    }

}
